
//是否正确手机号
function checkMp(mp){ 
	if(mp.length!=11){
		 return false; 
	}
    if(!(/^1[3|4|5|7|8][0-9]\d{4,8}$/.test(mp))){ 
        return false; 
    }else{
		return true;	
	}
} 
//商户报备提交校验
function perform5101() {
	var regbank = /^[\d-]{9,30}$/;
	var bkAcId = document.Form5101.bkAcId.value.trim();
	if (bkAcId == "") {
		alert("请输入银行帐号！");
		document.Form5101.bkAcId.focus();
		return;
	} else if (!regbank.test(bkAcId)) {
		alert("银行账号为9-30位，全部为数字也可以包含-！");
		document.Form5101.bkAcId.focus();
		return;
	}
	
	var bkAcName = document.Form5101.bkAcName.value.trim();
	if (bkAcName == "") {
		alert("请输入银行户名！");
		document.Form5101.bkAcName.focus();
		return;
	}
	var bkAcName = document.Form5101.dateOpen.value.trim();
	if (bkAcName == "") {
		alert("增机日期不能为空！");
		return;
	}
	//终端型号校验
	var modelid = document.getElementsByName("modelid");
	if(modelid.value!=""){
		for(var i=0;i<modelid.length-1;i++){
			if(modelid[i].value==""){
				alert("请选择终端型号！");
				return;
			}
		}
	}else{
		alert("请选择终端型号！");
	}
	for(var i=0;i<modelid.length-1;i++){
		for(var j=i+1;j<modelid.length-1;j++){
			if(modelid[i].value.trim()==modelid[j].value.trim()){
				alert("终端型号“"+modelid[i].value+"”不可以重复！");
				return;
			}
		}
	}
	var gettermtype = document.getElementsByName("gettermtype");
	
	var regJinE = /^((0\.[0-9][0-9])|(0\.[0-9][0-9])|([1-9]{1}[0-9]{0,8}\.([0-9])[0-9])|(0))$/;
	var terminalPrice = document.getElementsByName("terminalPrice");
	var mailLinkMan = document.getElementsByName("mailLinkMan");
	var mailMobileId = document.getElementsByName("mailMobileId");
	var mailsave = document.getElementsByName("mailsave");
	var mailcity = document.getElementsByName("mailcity");
	var maildetailed = document.getElementsByName("maildetailed");
	if(gettermtype!=""){
		for(var i=0;i<gettermtype.length-1;i++){
			if(gettermtype[i].value==''){
				alert("请选择机具模式！");
				return;
			} 
			if(gettermtype[i].value=='1'){
				if (terminalPrice[i].value == "") {
					alert("机具金额不能为空！");
					document.Form5101.terminalPrice[i].focus();
					return;
				}else if (!regJinE.test(terminalPrice[i].value)) {
					alert("请输入正确机具金额,必须保留两位小数，可以为零！");
					document.Form5101.terminalPrice[i].focus();
					return;
				}
			}
			
			if(gettermtype[i].value!='2'){
				//邮寄联系人
				if(mailLinkMan[i].value==''){
					alert("邮寄联系人不能为空！");
					document.Form5101.mailLinkMan[i].focus();
					return;
				}
				//邮寄联系人手机号	
				if(mailMobileId[i].value==''){
					alert("邮寄联系人手机号不能为空！");
					document.Form5101.mailMobileId[i].focus();
					return;
				}
				if(!checkMp(mailMobileId[i].value.trim())){
					alert("邮寄联系人手机号格式不正确！");
					document.Form5101.mailMobileId[i].focus();
					return;
				}
				//邮寄地址（省）
				if(mailsave[i].value==''){
					alert("邮寄地址（省）不能为空！");
					document.Form5101.mailsave[i].focus();
					return;
				}
				//邮寄地址（市）
				if(mailcity[i].value==''){
					alert("邮寄地址（市）不能为空！");
					document.Form5101.mailcity[i].focus();
					return;
				}
				//邮寄地址（明细）
				if(maildetailed[i].value==''){
					alert("邮寄地址（详细地址）不能为空！");
					document.Form5101.maildetailed[i].focus();
					return;
				}
			}
		}
	}else{
		alert("请选择机具模式！");
	}
	
	
	var terminaldeptFlag = document.getElementsByName("terminaldeptFlag");
	var terminalAmt = document.getElementsByName("terminalAmt");
	if(terminaldeptFlag!=""){
		for(var i=0;i<terminaldeptFlag.length-1;i++){
			if(terminaldeptFlag[i].value=='0'){
				if (terminalAmt[i].value == "") {
					alert("机具押金不能为空！");
					document.Form5101.terminalAmt[i].focus();
					return;
				}
				if (!regJinE.test(terminalAmt[i].value)) {
					alert("请输入正确机具押金,必须保留两位小数，可以为零！");
					document.Form5101.terminalAmt[i].focus();
					return;
				}
			}
			if(terminalAmt[i].value != ""){
				if(!regJinE.test(terminalAmt[i].value.trim())){
					alert("机具押金输入格式不正确！");
					document.Form5101.terminalAmt[i].focus();
					return;
				}
			}
		}
	}else{
		alert("请选择是否需要押金！");
	}
	
	var terminalNum = /^([1]{1}[0-9]{3}|[1-9]{1}[0-9]{0,2}|(2000))$/;
	//机具数量
	var terminalnum = document.getElementsByName("terminalnum");
	for(var i=0;i<terminalnum.length-1;i++){
		if(terminalnum[i].value==''){
			alert("请输入机具数量！");
			document.Form5101.terminalnum[i].focus();
			return;
		}
		if(!terminalNum.test(terminalnum[i].value.trim())){
			alert("机具数量必须为大于0小于等于2000的整数！");
			document.Form5101.terminalnum[i].focus();
			return;
		}
	}
	
	var simdeptFlag = document.getElementsByName("simdeptFlag");
	var simPrice = document.getElementsByName("simPrice");//SIM卡单价
	//SIM卡数量
	var simnum = document.getElementsByName("simnum");
	if(simdeptFlag!=""){
		for(var i=0;i<simdeptFlag.length-1;i++){
			if(simdeptFlag[i].value==''){
				alert("请选择是否需要SIM卡！");
				return;
			}
			if(simdeptFlag[i].value=='0'){
				if(simPrice[i].value==''){
					alert("请输入SIM卡押金！");
					document.Form5101.simPrice[i].focus();
					return;
				}
				if(!regJinE.test(simPrice[i].value.trim())){
					alert("请输入正确SIM卡押金,必须保留两位小数，可以为零！");
					document.Form5101.simPrice[i].focus();
					return;
				}
				if(simnum[i].value==''){
					alert("请输入SIM卡数量！");
					document.Form5101.simnum[i].focus();
					return;
				}
				if(!terminalNum.test(simnum[i].value.trim())){
					alert("SIM卡数量必须为大于0小于等于2000的整数！");
					document.Form5101.simnum[i].focus();
					return;
				}
			}
			if(simPrice[i].value != ""){
				if(!regJinE.test(simPrice[i].value.trim())){
					alert("SIM卡押金输入格式不正确！");
					document.Form5101.simPrice[i].focus();
					return;
				}
			}
			if(simnum[i].value != ""){
				if(!terminalNum.test(simnum[i].value.trim())){
					alert("SIM卡数量输入格式不正确！");
					document.Form5101.simnum[i].focus();
					return;
				}
			}
		}
	}else{
		alert("请选择是否需要押金！");
	}
	
	//装机联系人
	var installLinkMan = document.getElementsByName("installLinkMan");
	for(var i=0;i<installLinkMan.length-1;i++){
		if(installLinkMan[i].value==''){
			alert("装机联系人不能为空！");
			document.Form5101.installLinkMan[i].focus();
			return;
		}
	}	
	
	//装机联系人手机号	
	var installMobileId = document.getElementsByName("installMobileId");
	for(var i=0;i<installMobileId.length-1;i++){
		if(installMobileId[i].value==''){
			alert("装机联系人手机号不能为空！");
			document.Form5101.installMobileId[i].focus();
			return;
		}
		if(!checkMp(installMobileId[i].value.trim())){
			alert("装机联系人手机号格式不正确！");
			document.Form5101.installMobileId[i].focus();
			return;
		}
	}
	
	//装机地址（省）
	var installsave = document.getElementsByName("installsave");
	for(var i=0;i<installsave.length-1;i++){
		if(installsave[i].value==''){
			alert("装机地址（省）不能为空！");
			document.Form5101.installsave[i].focus();
			return;
		}
	}
	//装机地址（市）
	var installcity = document.getElementsByName("installcity");
	for(var i=0;i<installcity.length-1;i++){
		if(installcity[i].value==''){
			alert("装机地址（市）不能为空！");
			document.Form5101.installcity[i].focus();
			return;
		}
	}
	//装机地址（明细）
	var installdetailed = document.getElementsByName("installdetailed");
	for(var i=0;i<installdetailed.length-1;i++){
		if(installdetailed[i].value==''){
			alert("装机地址（详细地址）不能为空！");
			document.Form5101.installdetailed[i].focus();
			return;
		}
	}
	
	for(var i=0;i<mailsave.length-1;i++){
		document.getElementsByName("mailsave")[i].disabled="";
		document.getElementsByName("mailcity")[i].disabled="";
	}
	
	document.Form5101.submit();
}

